package com.lovo.sqlatm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Savers extends JPanel implements ActionListener {
    private Test0 frame;
private JTextField save =new JTextField();
private Icon conImage = Util.getIcon("/img/buttonSure.jpg");
    private Icon cancelImage = Util.getIcon("/img/buttonOff.jpg");
private JButton confirmButton;
private JButton cancelButton;


    public Savers(Test0 frame) {
        this.frame=frame;

        this.setLayout(null);
        //存款提示
        JLabel saveText = new JLabel("请输入你要存款的金额：");
        saveText.setBounds(314, 338, 160, 40);
        this.add(saveText);
        //输入存款金额
         save.setBounds(454,338,150,40);
         save.getText();
         this.add(save);

         //确认按钮
        confirmButton=new JButton(conImage);
        confirmButton.setBounds(354,400,140,50);
        confirmButton.addActionListener(this);
        this.add(confirmButton);
        //返回按钮
        cancelButton=new JButton(cancelImage);
        cancelButton.setBounds(540,400,140,50);
        this.add(cancelButton);
        cancelButton.addActionListener(this);

        this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==confirmButton){

            int saveMoney = Integer.parseInt(save.getText());

            JdbcUtil jdbcUtil =new JdbcUtil();
            Uesr uesr = jdbcUtil.selectId(frame.getUesr().getId());
            uesr.setBalance(uesr.getBalance()+saveMoney);
            jdbcUtil.update(uesr);


JOptionPane.showMessageDialog(this,uesr.getBalance());

        }else if (e.getSource()==cancelButton){
                frame.switchPanel("menu");
        }

    }
}
